#!/usr/bin/env python

import unittest

from amlnextbus.stop import Stop

class TestStop(unittest.TestCase):
    def setUp(self):
        self.stop = Stop('10', '10_OB1')

    def testParseStop(self):
        testStr1 = """
      parent.addOption(stopSelector, 
                 "San Jose Ave & Geneva Ave", 
		      	        "6347", 
							 false, 
										 false);

"""
        (name, symbol, restOfStr) = self.stop.parseStop(testStr1)

        self.assertEquals(name, "San Jose Ave & Geneva Ave")
        self.assertEquals(symbol, "6347")

        testStr2 = """
        parent.addOption(toStopSelector,
                         "Right Of Way & Liberty St",
                         "6222",
                         false,
                         false);  // specifies which item is selected

        parent.addOption(toStopSelector,
                         "Right Of Way & 20th St",
                         "6215",
                         false,
                         false);  // specifies which item is selected

        parent.addOption(toStopSelector,
                         "Right Of Way & 18th St",
                         "6213",
                         false,
                         false);  // specifies which item is selected

        parent.addOption(toStopSelector,
                         "Church St & 16th St",
                         "3985",
                         false,
                         false);  // specifies which item is selected

        parent.addOption(toStopSelector,
                         "Church St & Market St",
                         "7073",
                         false,
                         false);  // specifies which item is selected
"""
        expectedNameArr = ["Right Of Way & Liberty St",
                           "Right Of Way & 20th St",
                           "Right Of Way & 18th St",
                           "Church St & 16th St",
                           "Church St & Market St"]
        expectedSymbolArr = ["6222", "6215", "6213", "3985", "7073"]

        (name, symbol, restOfHtmlStr) = self.stop.parseStop(testStr2)
        i = 0
        while (restOfHtmlStr != None):
            self.assertEquals(name, expectedNameArr[i])
            self.assertEquals(symbol, expectedSymbolArr[i])
        
            i += 1
            (name, symbol, restOfHtmlStr) = self.stop.parseStop(restOfHtmlStr)

    def testLoadStops(self):
        self.assertTrue(len(self.stop.nameArr) > 0)
        self.assertTrue(len(self.stop.symbolArr) > 0)

    def testGetName(self):
        self.assertEquals(self.stop.getName("6694"), "Townsend St & 4th St")
        self.assertEquals(self.stop.getName("6696"), "Townsend St & 5th St")
        self.assertEquals(self.stop.getName("6698"), "Townsend St & 6th St")

    def testGetSymbol(self):
        self.assertEquals(self.stop.getSymbol("23rd St & Dakota"), "7545")
        self.assertEquals(self.stop.getSymbol("14 Dakota St"), "4342")
        self.assertEquals(self.stop.getSymbol("25th St & Dakota St"), "3507")


if __name__ == '__main__':
    unittest.main()


